<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="common/includeAdmin::header('日志管理','')"></head>
<body class="childrenBody">
	<form class="layui-form">
		<blockquote class="layui-elem-quote quoteBox">
			<form class="layui-form">
				<div class="layui-inline">
					<div class="layui-input-inline">
						<input type="text" class="layui-input searchVal"
							placeholder="请输入搜索的内容" />
					</div>
					<a class="layui-btn search_btn" data-type="reload">搜索</a>
				</div>
				<div class="layui-inline">
					<a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>
				</div>
			</form>
		</blockquote>
		<table id="sysLogList" lay-filter="sysLogList"></table>

		<!--操作-->
		<script type="text/html" id="sysLogBar">
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
	</script>
	</form>
	<div th:include="common/includeAdmin::footer"></div>
	<script type="text/javascript">
	layui.use([ 'layer', 'table' ], function() {
		var $ = layui.jquery;
		var layer = parent.layer === undefined ? layui.layer : top.layer;
		var table = layui.table;

		var tableIns = table.render({
			elem : '#sysLogList',
			// url : '/json/sysConfig.json',
			url : "/sys/log/",
			page : true,
			loading : true,
			height : 'full-110',
			limit : 10,
			limits : [ 10, 15, 20, 25 ],
			id : "sysLogTable",
			cols : [ [ {
				type : 'checkbox'
			}, {
				field : 'userName',
				width : 120,
				title : '操作用户',
				sort : true
			}, {
				field : 'operation',
				width : 160,
				title : '操作描述'
			}, {
				field : 'method',
				width : 200,
				title : '操作方法',
				sort : true
			}, {
				field : 'params',
				title : '参数',
				width : 120
			}, {
				field : 'useTime',
				title : '响应时间(ms)',
				width : 100,
				sort : true
			}, {
				field : 'ip',
				title : 'IP地址',
				width : 120
			} // minWidth：局部定义当前单元格的最小宽度，layui 2.2.1 新增
			, {
				field : 'createDate',
				title : '创建时间',
				width : 120,
				sort : true,
				templet : function(d) {
					return d.createDate.substring(0, 10);
				}
			}, {
				field : 'updateDate',
				title : '更新时间',
				minWidth : 130,
				sort : true,
				templet : function(d) {
					return d.updateDate.substring(0, 10);
				}
			}, {
				title : '操作',
				width : 170,
				templet : '#sysLogBar',
				fixed : "right",
				align : "center"
			} ] ]
		});
		// 列表操作
		table.on('tool(sysLogList)', function(obj) {
			var layEvent = obj.event, data = obj.data;
			if (layEvent === 'del') { // 删除
				layer.confirm('确定删除此日志吗？', {
					icon : 3,
					title : '提示信息'
				}, function(index) {
					remove(data.id);
					tableIns.reload();
					layer.close(index);
					// })
				});
			}
		});
		
		function remove(id){
			B.del({
				url:"/sys/log/"+id,
				loading:true,
				success:function(data){
					if(data.code==0){
						B.msg("删除成功");
						tableIns.reload();
					}
				}
			});
		}
		$(".search_btn").click(function() {
			if($(".searchVal").val() != ''){
	            table.reload("sysLogTable",{
	                page: {
	                    curr: 1 //重新从第 1 页开始
	                },
	                where: {
	                	operation: $(".searchVal").val()  //搜索的关键字
	                }
	            })
	        }else{
	            layer.msg("请输入搜索的内容");
	        }
		});
		$('.delAll_btn').click(function(){
			var checkStatus = table.checkStatus('sysLogTable'),
	        data = checkStatus.data,
	        ids = [];
		    if(data.length > 0) {
		        for (var i in data) {
		            ids.push(data[i].id);
		        }
		        layer.confirm('确定删除选中的数据？', {icon: 3, title: '提示信息'}, function (index) {
		            remove(ids);
		            tableIns.reload();
		            layer.close(index);
		            // })
		        })
		    }else{
		        layer.msg("请选择需要删除数据");
		    }
		});
	})
	
	</script>
</body>
</html>

